package com.wjw.controller.system;

import com.wjw.entity.Employee;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * thymeleaf语法学习：
 * http://127.0.0.1:8081/springboot/thymeleaf/view
 */
@Controller
@RequestMapping("/thymeleaf")
public class ThymeleafController {

    private String prefix = "thymeleaf/";//跳转页面的前缀

    @GetMapping("/view")
    public String view(ModelMap mmap, HttpSession session){
        //传普通类型
        mmap.put("string","字符串");
        mmap.put("int",123456);
        mmap.put("boolean",false);
        //传html
        mmap.put("baidu","<a href='http://www.baidu.com'>百度一下</a>");
        //传对象
        mmap.put("employee",new Employee(1L,"吴佳威",new Date(),12345.66d,"男",""));
        //传List
        List<Employee> empList = Arrays.asList(new Employee(1L,"吴佳威",new Date(),999999.99,"男",""),
                                               new Employee(2L,"吴彦祖",new Date(),666666.66,"男",""),
                                               new Employee(3L,"吴佳豪",new Date(),888888.88,"男",""),
                                               new Employee(4L,"吴清风",new Date(),888866.88,"男",""));
        mmap.put("empList",empList);
        //session传值
        session.setAttribute("sessionData","保存在session中的字符串");
        return prefix + "view";
    }

}

